package org.strategies.dao.impl;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;
import org.strategies.dao.AbstractDao;
import org.strategies.dao.TestDao;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by DevMode on 06.01.14.
 */
@Repository
public class TestDaoImpl extends AbstractDao implements TestDao {

    public Map<Integer, BigDecimal> getEurUsdIncome() {
        return jdbc.query(getQuery("selectEurUsdIncome"), new ResultSetExtractor<Map<Integer,BigDecimal>>() {
            @Override
            public Map<Integer,BigDecimal> extractData(ResultSet rs) throws SQLException, DataAccessException {
                Map<Integer, BigDecimal> result = new HashMap<Integer, BigDecimal>();
                while (rs.next()) {
                    Integer year = rs.getInt(1);
                    BigDecimal totalIncome = rs.getBigDecimal(2);
                    result.put(year, totalIncome);
                }
                return result;
                }
            });
    }
}
